#include<bits/stdc++.h>

using namespace std;
char *action[12][6] = {"S5#", NULL, NULL, "S4#", NULL, NULL,           /*ACTION±í*/
                       NULL, "S6#", NULL, NULL, NULL, "acc",
                       NULL, "r2#", "S7#", NULL, "r2#", "r2#",
                       NULL, "r4#", "r4#", NULL, "r4#", "r4#",
                       "S5#", NULL, NULL, "S4#", NULL, NULL,
                       NULL, "r6#", "r6#", NULL, "r6#", "r6#",
                       "S5#", NULL, NULL, "S4#", NULL, NULL,
                       "S5#", NULL, NULL, "S4#", NULL, NULL,
                       NULL, "S6#", NULL, NULL, "S11#", NULL,
                       NULL, "r1#", "S7#", NULL, "r1#", "r1#",
                       NULL, "r3#", "r3#", NULL, "r3#", "r3#",
                       NULL, "r5#", "r5#", NULL, "r5#", "r5#",
};
int goto1[12][3] = {1, 2, 3,                        /*GOTO±í*/
                    0, 0, 0,
                    0, 0, 0,
                    0, 0, 0,
                    8, 2, 3,
                    0, 0, 0,
                    0, 9, 3,
                    0, 0, 10,
                    0, 0, 0,
                    0, 0, 0,
                    0, 0, 0,
                    0, 0, 0,
};
char vt[6] = {'i', '+', '*', '(', ')', '#'};                       /*′?·????á·?*/
char vn[3] = {'E', 'T', 'F'};                                 /*′?·?·????á·?*/
char *LR[7] = {"S->E#", "E->E+T#", "E->T#", "T->T*F#", "T->F#", "F->(E)#", "F->i#"};
/*′?·?2úéúê?*/

int a[13];
char b[13], c[13], c1;
int top1, top2, top3, top, m, n;

bool slr(const string &w) {
    int g, h, i, j, k, l, p, y, z, count;
    char x, copy[30], copy1[30];
    top1 = 0;
    top2 = 0;
    top3 = 0;
    top = 0;
    a[0] = 0;
    y = a[0];
    b[0] = '#';
    count = 0;
    z = 0;
    i = 0;
    do {
        c1 = w[i];
        c[top3] = c1;
        top3 = top3 + 1;
        i++;
    } while (c1 != '#');
    do {
        y = z;
        m = 0;
        n = 0;                      /*y,z???ò×′ì??????￥*/
        g = top;
        j = 0;
        k = 0;
        x = c[top];
        count++;
        // printf("%d\t", count);
        while (m <= top1) {                    /*ê?3?×′ì???*/
            //   printf("%d", a[m]);
            m = m + 1;
        }
        //printf("\t\t");
        while (n <= top2) {                    /*ê?3?·?o???*/
            //  printf("%c", b[n]);
            n = n + 1;
        }
        //printf("\t\t");
        while (g < top3) {                    /*ê?3?ê?è?′?*/
            // if (g > 0)printf("%c", c[g]);
            g = g + 1;
        }
        // printf("\t\t");
        while (x != vt[j] && j <= 4) j++;
        if ( j == 4 && x != vt[j] ) {
            //printf("error\n");
            return 0;
        }
        if ( action[y][j] == NULL ) {
            //printf("error\n");
            return 0;
        } else
            strcpy(copy, action[y][j]);
        if ( copy[0] == 'S' ) {                      /*′|àíò???*/
            z = copy[1] - '0';
            top1 = top1 + 1;
            top2 = top2 + 1;
            a[top1] = z;
            b[top2] = x;
            top = top + 1;
            i = 0;
            while (copy[i] != '#') {
                //  printf("%c", copy[i]);
                i++;
            }
            // printf("\n");
        }
        if ( copy[0] == 'r' ) {                      /*′|àí1é??*/
            i = 0;
            while (copy[i] != '#') {
                // printf("%c", copy[i]);
                i++;
            }
            h = copy[1] - '0';
            strcpy(copy1, LR[h]);
            while (copy1[0] != vn[k]) k++;
            l = strlen(LR[h]) - 4;
            top1 = top1 - l + 1;
            top2 = top2 - l + 1;
            y = a[top1 - 1];
            p = goto1[y][k];
            a[top1] = p;
            b[top2] = copy1[0];
            z = p;
            // printf("\t");
            // printf("%d\n", p);
        }
    } while (action[y][j] != "acc");
    return true;
}

int main() {
    //  freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    for (string w; cin >> w;) {
        if ( slr(w)) {
            cout << "syntax correct" << endl;
        } else {
            cout << "syntax error" << endl;
        }
    }

}
/**************************************************************
    Problem: 4021
    User: acm
    Language: C++
    Result: 正确
    Time:5 ms
    Memory:2180 kb
    Judger:judge.master
****************************************************************/